# encoding:utf-8

import sys
from workflow import Workflow3, ICON_ACCOUNT

ssh_list = [{"tag": "test", "host": "123.456.789.xx",
             "port": "18222", "name": "root", "desc": "测试服务器"},
            {"tag": "nodes", "host": "213.342.789.xx",
             "port": "18322", "name": "root", "desc": "生产服务器"}]
query = None
if len(sys.argv) > 1:
    query = sys.argv[1]


def list_all(wf):
    for item in ssh_list:
        if query is None or query in item["tag"] or query in item["host"]:
            ssh_suffix = "{name}@{host}:{port}".format(name=item["name"],
                                                       host=item["host"], port=item["port"])
            wf.add_item(title="{desc}({tag})".format(tag=item["tag"], desc=item["desc"]),
                        valid=True, icon=ICON_ACCOUNT,
                        arg="-p {port} {name}@{host}".format(name=item["name"],
                                                       host=item["host"], port=item["port"]),
                        subtitle=ssh_suffix)

    wf.send_feedback()


if __name__ == '__main__':
    wf = Workflow3()
    sys.exit(wf.run(list_all))
